/*
 * @Author: Qimu
 * @Date: 2020-04-22 15:55:22
 * @LastEditors: Qimu
 * @LastEditTime: 2020-06-28 22:53:06
 * @Description: file content
 * @FilePath: \vue-admin-koa2\koa2_api\module\schama\submenu.js
 */

const mongoose = require('../db/mongodb');
const config = require('../config/config');

const submenuSchema = mongoose.Schema({
  parent_id: { //关联一级菜单ID
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Menu'
  },//这里即为子表的外键，关联主表.ref后的Menu代表的是主表Menu的Model。
  menu_name: { //二级菜单名称
    type: String,
    require: true,
    trim: true
  },
  menu_level: { //二级菜单权限
    type: Number,
    require: true,
    trim: true
  },
  menu_path: {  //菜单路径
    type: String,
    require: true,
    trim: true
  },
  menu_status: {  //菜单是否显示
    type: Number,
    default: 1
  },
  submenu_createTime: { //菜单创建时间
    type: Date,
    default: Date.now
  },
  submenu_updateTime: { //菜单更新时间
    type: Date,
    default: Date.now
  }
}, {
  timestamps: {
    createdAt: 'submenu_createTime',
    updatedAt: 'submenu_updateTime'
  }
})

module.exports = Submenu = mongoose.model('Submenu', submenuSchema, `${config.mongodb.table}submenu`);